﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Windows.Documents;
using ResourceBlender.Core;

namespace ResourceBlender.Express {
    /// <summary>
    /// Formats a response from WordNet using a XAML template.
    /// </summary>
    public class WordNetFormatter {
        /// <summary>
        /// Formats a DefinitionCollection as a FlowDocument.
        /// </summary>
        /// <param name="results">The results.</param>
        /// <returns>A FlowDocument, or <c>null</c> if the XAML template could not be loaded.</returns>
        public static FlowDocument FormatResults(DefinitionCollection results) {
            FlowDocument doc = null;
            try {
                object xaml = System.Windows.Application.LoadComponent(new Uri(@"/;component\WordNet\ResultsTemplate.xaml", UriKind.Relative));
                doc = xaml as FlowDocument;
                doc.DataContext = results;
            } catch {
                throw new ResourceBlenderException("Error loading results template");
            }
            return doc;
        }
    }
}
